
package com.opensymphony.clickstream;

import java.io.Serializable;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.probiz.estore.webapp.util.RequestUtil;

/**
 * A small class that captures the most important info from the
 * HttpServletRequest for each "click". See the documentation for
 * HttpServletRequest for more info about each method here.
 * 
 * @author <a href="plightbo@hotmail.com">Patrick Lightbody </a>
 *         modifier:chenshangxuan 2006-07-17
 */
public class ClickstreamRequest implements Serializable {
	private static final long	serialVersionUID	= 5639178846343270927L;

	// the click counts which current user click this url.
	private int					clickCounts;

	private String				cookieId;

	private int					prevRequestIndex;

	private String				remoteUser;

	private String				returnView;

	// the interval user stay in this url page,by secnods.
	private int					timeInterval;

	private Date				timestamp;

	// page url the user visited
	private String				url;

	public ClickstreamRequest(HttpServletRequest request, Date timestamp) {
		remoteUser = request.getRemoteUser();
		this.timestamp = timestamp;
		clickCounts = 1;
		timeInterval = 0;
		returnView = request.getParameter("ReturnView");
		url = RequestUtil.getFullRequestUrl(request);
		// Cookie cookie = RequestUtil.getEStoreCookie(request);
		// if (cookie != null) {
		// cookieId = cookie.getValue();
		// }
	}

	public int getClickCounts() {
		return clickCounts;
	}

	public String getCookieId() {
		return cookieId;
	}

	public int getPrevRequestIndex() {
		return prevRequestIndex;
	}

	public String getRemoteUser() {
		return remoteUser;
	}

	public String getReturnView() {
		return this.returnView;
	}

	public int getTimeInterval() {
		return timeInterval;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public String getUrl() {
		return url;
	}

	public void setClickCounts(int clickCounts) {
		this.clickCounts = clickCounts;
	}

	public void setPrevRequestIndex(int prevRequestIndex) {
		this.prevRequestIndex = prevRequestIndex;
	}

	public void setTimeInterval(int timeInterval) {
		this.timeInterval = timeInterval;
	}

	/**
	 * Returns a string representation of the HTTP request being tracked.
	 * Example: <b>www.opensymphony.com/some/path.jsp?arg1=foo&arg2=bar </b>
	 * 
	 * @return a string representation of the HTTP request being tracked.
	 */
	@Override
	public String toString() {
		return url;
	}
}